﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MsForgeReboot.Tests.Controllers {
    using System.Collections.Generic;
    using System.Web.Mvc;

    using Moq;

    using MsForgeReboot.Framework.Entities;
    using MsForgeReboot.Framework.Interfaces;
    using MsForgeReboot.Web.Controllers;

    using PagedList;

    [TestClass]
    public class EventControllerTests {
        private Mock<IEventService> eventService;

        [TestInitialize]
        public void TestInitialize() {
            this.eventService = new Mock<IEventService>();
        }

        public void TestCleanup() {
            this.eventService = null;
        }

        [TestMethod]
        public void GetUpcomingEventsReturnsListOfEvents() {
            this.eventService.Setup(service => service.UpcomingEvents(1, 10))
                .Returns(new List<Event>().ToPagedList(1, 10));

            var target = new EventController(this.eventService.Object);
            var result = target.Index(1, 10) as ViewResult;

            Assert.IsInstanceOfType(result.Model, typeof(IPagedList<Event>));

            this.eventService.Verify();
        }

        [TestMethod]
        public void ShowEventDetails() {
            this.eventService.Setup(service => service.GetByUrlPointer("Event Title 1"))
                    .Returns(new Event { Id = 123, Title = "Event Title 1" , Topic = "Testing", Begin = DateTime.Now.AddDays(1), End = DateTime.Now.AddDays(1), Body = "Description"});

            var target = new EventController(this.eventService.Object);
            var result = target.Details("Event Title 1") as ViewResult;
            var model = (Event)result.Model;

            Assert.IsInstanceOfType(result.Model, typeof(Event));
            Assert.AreEqual("Event Title 1", model.Title);

            this.eventService.Verify(context => context.GetByUrlPointer("Event Title 1"),Times.Once);
            
        }

    }
}
